<template>
  <el-dialog
    :title="title"
    :visible.sync="innerVisible"
    width="600px"
    @close="handleCancel"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="formRef"
      label-width="180px"
    >
      <el-form-item label="年度" prop="year">
        <el-select
          placeholder="年度"
          v-model="form.year"
          clearable
          :disabled="isDetail"
        >
          <el-option
            v-for="item in yearList"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="form.enterpriseName"
          placeholder="请输入"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="预计孵化时间">
        <el-date-picker
          v-model="form.planCompleteTime"
          type="date"
          :disabled="isDetail"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="实际孵化时间">
        <el-date-picker
          v-model="form.completeTime"
          type="date"
          :disabled="isDetail"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="成果转化营业收入">
        <el-input
          v-model="form.resultInvestment"
          placeholder=""
          type="number"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="联系人及方式">
        <el-input
          v-model="form.contract"
          placeholder="如李某某，13800138000"
          :disabled="isDetail"
        />
      </el-form-item>

      <el-form-item label="是否为规上企业">
        <el-radio-group
          v-model="form.hasStandard"
          :disabled="isDetail"
        >
          <el-radio label="是"></el-radio>
          <el-radio label="否"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="是否为高精技术企业">
        <el-radio-group
          v-model="form.hasTechnology"
          :disabled="isDetail"
        >
          <el-radio label="是"></el-radio>
          <el-radio label="否"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="是否为专精特新企业">
        <el-radio-group
          v-model="form.hasMastery"
          :disabled="isDetail"
        >
          <el-radio label="是"></el-radio>
          <el-radio label="否"></el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>

    <div
      slot="footer"
      class="dialog-footer"
      v-if="!isDetail"
    >
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ProgressDialog',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      default: '填写信息'
    },
    isDetail: {
      type: Boolean
    },
    currentData: {
      type: Object
    }
  },
  data() {
    return {
      form: {
        pkid: '',
        year: '',
        enterpriseName: '',
        hasStandard: '是',
        hasTechnology: '是',
        hasMastery: '是',
        planCompleteTime: '',
        completeTime: '',
        contract: '',
        resultInvestment: ''
      },
      rules: {
        year: [
          {
            required: true,
            message: '请选择年份',
            trigger: 'blur'
          }
        ],
        enterpriseName: [
          {
            required: true,
            message: '请输入企业名称',
            trigger: 'blur'
          }
        ]
      },
      innerVisible: false,
      yearList: []
    }
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
    innerVisible(val) {
      this.$emit('update:visible', val)
    },
    currentData(val) {
      this.form = val
    }
  },
  mounted() {
    const year = new Date().getFullYear()
    this.yearList = [year, year - 1]
  },
  methods: {
    handleCancel() {
      this.$emit('update:visible', false)
    },
    handleConfirm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          this.$emit('confirm', { ...this.form })
          this.handleCancel()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/dialog.scss';
::v-deep .el-input__inner {
  width: 280px !important;
}
</style>
